package com.buddy.design.pattern._09decorator;

import com.buddy.design.pattern._09decorator.battercake.BaseBatterCake;
import com.buddy.design.pattern._09decorator.battercake.BatterCake;
import com.buddy.design.pattern._09decorator.battercake.EggDecorator;
import org.junit.Test;

public class DecoratorPattern {

    /*
     * 装饰者模式：
     *      在不改变原有对象的基础上，将功能附加到对象之上，提供了比继承更有弹性的替换方案（扩展原有对象的功能）
     *  符合开闭原则
     *
     *  属于结构性模式
     *
     *  BufferedReader
     *
     *  被装饰者作为参数 InputStream->FileInputStream
     *  TransactionAwareCacheDecorator
     *  HttpHeadResponseDecorator
     *
     *
     *  扩展原来的对象，与静态代理类似，但符合is-a的关系
     */

    @Test
    public void batterCakeTest(){
        //使用类的形式，一层层往下套
        BatterCake batterCake;

        batterCake = new BaseBatterCake();

        batterCake = new EggDecorator(batterCake);
        batterCake = new EggDecorator(batterCake);
        System.out.println(batterCake.getMsg()+":"+batterCake.getPrice());
    }
}
